package thread.concurrents;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 有界队列
 *
 * @author yincy
 */
public class ArrayBlockingQueueThread {

  //测试队列异常处理
  public static void main(String[] args) {

    LinkedBlockingQueue<Integer> queue2 = new LinkedBlockingQueue<>(10);

    try {
      queue2.put(1);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          while (true) {
            Integer take = queue2.poll(2000, TimeUnit.MILLISECONDS);
            System.out.println(take);
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    });

    thread.start();


  }

}

